package com.yeban.javase.day13.learn;

import java.io.*;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/10/23
 *
 * FileWriter   字符流     输出流
 */
public class FileWriterDemo {

    public static void main(String[] args) {

        // 创建文件
        File file = new File("D:\\Code\\geek_learn\\JavaSE\\src\\com\\yeban\\javase\\day13\\demo\\aaa\\demo.txt");
        try {
            if(!file.exists()){
                file.createNewFile();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        // 写入
        try(
                FileWriter fw = new FileWriter(file.getAbsoluteFile(),true);
        ) {
            fw.write('A');
            fw.write('\n');
            fw.write("b");
            fw.write('\n');
            String str1 = "Hello Wrold!";
            fw.write(str1);
            String str2 = "你好！Java！";
            fw.write(str2);
            fw.write(23);
            fw.write(str2.toCharArray());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
